<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        form {
            width: 460px;
            height: 550px;
            background-color: blueviolet;
            position: relative;
            margin: 50px auto;
            padding-top: 10px;
        }

        input[type="text"] {
            height: 40px;
            width: 250px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            outline: none;
        }

        input[type="password"] {
            height: 40px;
            width: 250px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            outline: none;
        }

        .username {
            top: 60px;
        }

        .password {
            top: 120px;
        }

        .tel {
            top: 180px;
        }

        .sex {
            width: 250px;
            position: absolute;
            top: 250px;
            left: 50%;
            transform: translateX(-50%);
        }

        button {
            width: 140px;
            height: 50px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            background-color: deeppink;
        }

        .regist {
            top: 310px;
        }

        .login {
            top: 380px;
        }
        .check {
            position: absolute;
            top: 70px;
            right: 20px;
            font-size: 12px;
        }
        h1{
            text-align: center;
        }
    </style>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
</head>

<body>
<form>
    <h1>用户注册</h1>
    <input type="text" name="username" placeholder="姓名" class="username" autocomplete="off"><span class="check"></span>
    <input type="password" name="password" placeholder="密码" class="password">
    <input type="text" name="tel" placeholder="电话号码" class="tel">
    <div class="sex">
        性别:
        <input type="radio" name="sex" value="男" class="sex1">男
        <input type="radio" name="sex" value="女" class="sex1">女
    </div>
    <button type="button" class="regist">注册</button>
    <a href="login.html"><button class="login">登录</button></a>
</form>

<script>
    $(function(){
        // $(".username").blur(function(){
        //     if(!$(".username").val()){
        //         $(".check").html("用户名不能为空").css("color","#e93854")
        //         $(".logon").prop("disabled",true)
        //     }else{
        //         $.ajax({
        //             type:"POST",
        //             url:"/checkname",
        //             data: {
        //                 "username":$(".username").val()
        //             },
        //             success:function (check){
        //                 if (check=="true"){
        //                     $(".check").html("用户名已存在").css("color","#e93854")
        //                     $(".logon").prop("disabled",true)
        //                 }else{
        //                     $(".check").html("用户名可以使用").css("color","black")
        //                     $(".logon").prop("disabled",false)
        //                 }
        //             }
        //         })
        //     }
        // })
        $(".regist").click(function(){
           $.ajax({
               type: "post",
               url: "/regist.do",
               data: {
                   "username":$(".username").val(),
                   "password":$(".password").val(),
                   "sex":$(".sex1:checked").val(),
                   "tel":$(".tel").val()
               },
               success:function(data){
                   if (data==="true"){
                       alert("注册成功！")
                       location.href="login.html"
                   }
                   if (data==="false"){
                       alert("注册失败！")
                       location.href="regist.html"
                   }
               }
           })
        })
    })
</script>
</body>

</html>